Imports Microsoft.VisualBasic
Imports System.Collections.Generic
Imports System.Web.Configuration
Imports System.Data
Imports System.Data.SqlClient
Imports System.Transactions
Namespace WorkFlow.DAO
    Public Class VOrganizationDAO
        Inherits OAMS.DAO.BaseDAO
        Dim _dbName As String
        Public Sub New(ByVal dbName As String)
            _dbName = dbName
        End Sub
        Public Function InsertVOrg(ByVal VOrganizationName As String, ByVal OrganizationID As String, ByVal Active As String, ByVal OrganizationType As String, ByVal EstablishDate As String, ByVal MOIOrganizationType As String) As Integer
            Dim sql As New StringBuilder
            sql.AppendFormat("insert VOrganization (VOrganizationName,OrganizationID,Active,OrganizationType,EstablishDate,MOIOrganizationType) select ")
            sql.AppendFormat(" '{0}' ", VOrganizationName)

            sql.AppendFormat(",{0} ", OrganizationID)
            sql.AppendFormat(",'{0}' ", "Y")
            sql.AppendFormat(",'{0}' ", OrganizationType)

            sql.AppendFormat(",'{0:yyyy/MM/dd}' ", DateTime.Parse(EstablishDate))
            sql.AppendFormat(",'{0}' ", MOIOrganizationType)
            sql.AppendFormat("select @@identity ")
            Return Int32.Parse(SqlHelper.ExecuteScalar(MyConn(_dbName), CommandType.Text, sql.ToString()))
        End Function
        Public Sub UpdateVOrg(ByVal VOrganizationName As String, ByVal Active As String, ByVal EstablishDate As String, ByVal MOIOrganizationType As String, ByVal VOrganizationID As String)
            Dim sql As New StringBuilder


            sql.AppendFormat("update VOrganization set ")
            sql.AppendFormat(" VOrganizationName = '{0}' ", VOrganizationName)
            sql.AppendFormat(",Active = '{0}' ", Active)

            sql.AppendFormat(",EstablishDate = '{0:yyyy/MM/dd}' ", DateTime.Parse(EstablishDate))
            sql.AppendFormat(",MOIOrganizationType = '{0}' ", MOIOrganizationType)
            sql.AppendFormat("where VOrganizationID = {0} ", VOrganizationID)

            SqlHelper.ExecuteNonQuery(MyConn(_dbName), CommandType.Text, sql.ToString())
        End Sub
        Public Function GetVOrganization(ByVal VOrganizationID As String) As DataTable
            Dim sql As New MyStringBuilder

            sql.AppendFormat("select o.* from VOrganization o ")
            sql.AppendFormat("where o.VOrganizationID = {0} ", VOrganizationID)


            Return SqlHelper.ExecuteDataset(MyConn(_dbName), CommandType.Text, sql.ToString()).Tables(0)
        End Function
        Public Function GetDDLRegion() As DataTable
            Dim sql As New MyStringBuilder
            sql.AppendFormat(" select * from Region where RegionType='T' ")
            Return SqlHelper.ExecuteDataset(MyConn(_dbName), CommandType.Text, sql.ToString()).Tables(0)
        End Function
        Public Sub ChangeActiveStatus(ByVal status As String, ByVal VOrganizationID As String)
            Dim sql As New StringBuilder
            sql.AppendFormat("update VOrganization set ")
            sql.AppendFormat(" Active = '{0}' ", status)
            sql.AppendFormat("where VOrganizationID = '{0}' ", VOrganizationID)
            SqlHelper.ExecuteNonQuery(MyConn(_dbName), CommandType.Text, sql.ToString())
        End Sub
        Public Function GetAllVOrganization() As DataTable
            Dim sql As New MyStringBuilder

            sql.AppendFormat("select o.* from VOrganization o ")



            Return SqlHelper.ExecuteDataset(MyConn(_dbName), CommandType.Text, sql.ToString()).Tables(0)
        End Function
    End Class
End Namespace
